package com.xiqin.microserviceservice.base;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiqin.microservicedao.base.BaseMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @Author TaoQiansheng
 * @Date 2020-04-29 16:10
 * @Version 1.0
 */
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return baseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(T record) {
        return baseMapper.insert(record);
    }

    @Override
    public int insertSelective(T record) {
        return baseMapper.insertSelective(record);
    }

    @Override
    public T selectByPrimaryKey(Integer id) {
        return baseMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(T record) {
        return baseMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(T record) {
        return baseMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<T> selectByConditionsForPage(Map conditions) {
        Integer pageNum = null==conditions.get("pageNum")?1: (Integer) conditions.get("pageNum");
        Integer pageSize = null==conditions.get("pageSize")?100: (Integer) conditions.get("pageSize");
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<T> pageInfo = new PageInfo<>(this.selectByConditions(conditions));
        return pageInfo;
    }

    @Override
    public List<T> selectByConditions(Map conditions) {
        return baseMapper.selectByConditions(conditions);
    }
}
